﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;

public partial class admin_delCourseware : System.Web.UI.Page
{
    db_courseware courseware = new db_courseware();
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证

        string coursewareId = Request.QueryString["id"];
        //通过验证控件的验证
        if (coursewareId != null)
        {
            DataSet ds = courseware.selectCoursewareONE(coursewareId);

            if (courseware.delCourseware(coursewareId))
            {
                if (ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                    if (!"".Equals(ds.Tables[0].Rows[0]["coursewareUrl"].ToString()))
                    {
                        string serverpath = Server.MapPath(ds.Tables[0].Rows[0]["coursewareUrl"].ToString());
                        File.Delete(serverpath);
                    }
                }
                Response.Write("<script language=javascript>alert('删除成功！');location.href='manageCourseware.aspx';</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('删除失败！');location.href='manageCourseware.aspx';</script>");
            }

        }
        else
        {
            Response.Redirect("manageCourse.aspx");
        }

    }
}